/**
 移动页面Controller
 @class logs
 @author :laiwp
 @date:  :2016-07-01
 @version : 0.1.0
 @constructor : 0.1.0
 */
var config = require('../settings');
var log = require('../logger.js');
var tools = require('../tools.js');
var https = require('https');
var async = require('async');
var md5 = require('md5');

var moment = require('moment');
var superagent = require('superagent');
var settings = require('../settings');
module.exports = {
    mapping: {

        _sport_confirmOrder: {
            'url': '/sport/confirmOrder',
            'method': 'get',
            'description': '确认订单',
            'auth': false
        },

        _sport_order_add: {
            'url': '/sport/order/add',
            'method': 'post',
            'description': '添加订单',
            'auth': false
        },

    },



    //确认订单
    /**
     * 提交订单页面的确认界面,功能如下:
     * 1,查询session,获取wxid,将wxid传递到前台;
     * @param req
     * @param res
     * @private
     */
    _sport_confirmOrder: function (req, res) {
        console.log('--_sport_confirmOrder--',req.session);
        var wxopenId;
        if (req.session.member) {
            wxopenId = req.session.member.wxopenId;
        } else {
            wxopenId = 'ovKRTwQkp7YMnkAiqBV2retvNXSU';
        }
        console.log('--_sport_confirmOrder:--',config.title,'||',wxopenId);

        res.send({
            title: config.title,
            wxopenId: wxopenId
        })
    },

    //添加订单
    _sport_order_add: function (req, res) {

        var orderItems = req.body.orderItems;
        var phone = req.body.phone;
        var gymId = req.body.gymId;
        var wxopenid = req.body.wxopenid;

        var clmData = {
            channel: "WECHATQCG",
            gymId: gymId,
            phone: phone,
            userId:wxopenid,
            desc: "小时预定",
            data: orderItems
        };
        console.log(clmData);
        //请求订单
        var url = "http://123.57.72.140:3001/api/reserve/createOrderHours";
        //var url="http://192.168.2.168/api/reserve/createOrderHours";
        superagent.post(url).send(clmData).end(function (err, body) {
            console.log("=======================qqqqq===========",err,body.body);
            if (body.body.state === true) {
                res.send({'resultCode': '0', 'orderNo': body.body.orderId});
            } else {
                res.send({'resultCode': '99', 'datas': body.body.message});
            }
        })

    },
}
